package com.iweb.xt.web.service.impl;

import com.iweb.xt.common.model.CallResult;
import com.iweb.xt.common.service.AbstractTemplateAction;
import com.iweb.xt.web.domain.NewsDomain;
import com.iweb.xt.web.domain.repository.NewsDomainRepository;
import com.iweb.xt.web.model.NewsParam;
import com.iweb.xt.web.service.NewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NewServiceImpl extends AbstractService implements NewService {
    @Autowired
    private NewsDomainRepository newsDomainRepository;
    @Override
    public CallResult newList(NewsParam newsParam) {
      NewsDomain newsDomain= newsDomainRepository.createNewsDomain(newsParam);
        return this.serviceTemplate.executeQuery(new AbstractTemplateAction<Object>() {
//            检查参数

            @Override
            public CallResult<Object> checkParam() {
                return newsDomain.checkNewsListParam();
            }

            @Override
            public CallResult<Object> doAction() {
                return newsDomain.newList(false);
            }
        });
    }

    @Override
    public CallResult findNewsById(NewsParam newsParam) {
        NewsDomain newsDomain=newsDomainRepository.createNewsDomain(newsParam);
        return this.serviceTemplate.executeQuery(new AbstractTemplateAction<Object>() {
            @Override
            public CallResult<Object> doAction() {
                return newsDomain.findNewsById();
            }
        });
    }

    @Override
    public CallResult newsDetailList(NewsParam newsParam) {
        NewsDomain newsDomain=newsDomainRepository.createNewsDomain(newsParam);
        return this.serviceTemplate.executeQuery(new AbstractTemplateAction<Object>() {
            @Override
            public CallResult<Object> doAction() {
                return newsDomain.newList(true);
            }
        });
    }
}
